﻿using System.Globalization;
using System.Collections.Generic;

using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace RoslynTest.Analyzers.Lib
{
    internal class MethodComparer : IEqualityComparer<MethodDeclarationSyntax>
    {
        public bool Equals(MethodDeclarationSyntax m1, MethodDeclarationSyntax m2)
        {
            if (m1.Identifier.ValueText == m2.Identifier.ValueText &&
                m1.Identifier.SyntaxTree.FilePath == m2.Identifier.SyntaxTree.FilePath &&
                m1.Identifier.SpanStart == m2.Identifier.SpanStart)
            {
                return true;
            }

            return false;
        }

        public int GetHashCode(MethodDeclarationSyntax obj)
        {
            return
                (obj.Identifier.ValueText + obj.Identifier.SyntaxTree.FilePath +
                 obj.Identifier.SpanStart.ToString(CultureInfo.InvariantCulture)).GetHashCode();
        }
    }
}
